package com.itheima.controller;

import com.itheima.pojo.HmSubjects;
import com.itheima.service.SubjectService;
import com.itheima.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/subjects")
public class SubjectController {
    @Autowired
    private SubjectService subjectService;

    //学科修改
    @PutMapping("/{id}")
    public void updateById(@PathVariable Integer id, @RequestBody HmSubjects hmSubjects){
        subjectService.updateById(id,hmSubjects);
    }

    //学科删除
    @DeleteMapping("/{id}")
    public void del(@PathVariable Integer id){
        subjectService.del(id);
    }

    //学科添加
    @PostMapping
    public void add(@RequestBody HmSubjects hmSubjects){
        subjectService.add(hmSubjects);
    }

    //学科简单列表
    @GetMapping("/simple")
    public List simple(String subjectName){
        return subjectService.simple(subjectName);
    }

    //学科详情
    @GetMapping("/{id}")
    public HmSubjects getById(@PathVariable Integer id){
        return subjectService.getById(id);
    }

    //学科列表
    @GetMapping
    public PageResult list(Integer page,Integer pagesize,String subjectName){
        return subjectService.list(page,pagesize,subjectName);
    }
}
